import json
import os.path

import config_setting
from folder_scanner import read_and_parse_json_files
from util_store import read_entries


def update_name(path, content):
    content["Name"] = translation_dict[content["Id"]]
    # dir_path = os.path.dirname(path)
    # file = os.path.basename(path)
    # file_name, file_extension = os.path.splitext(file)
    # test_path = os.path.join(dir_path, file_name + "_r" + file_extension)
    with open(path, "w", encoding="utf-8") as file:
        # 使用ensure_ascii=False确保中文字符正常写入
        json.dump(content, file, ensure_ascii=False)


translation_dict = {}
translation_files = [
    f"name_translation_{config_setting.batch_name}.txt"
]

for translation_file in translation_files:
    translation_dict.update(read_entries(f"assets/step_1_2_translate_name/{translation_file}"))

folder_path = r"E:\PlayniteMetadata\games"  # 替换为你的文件夹路径
read_and_parse_json_files(folder_path, update_name)
